package com.szjlxh.data.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by liutao on 16/3/9.
 */
public class DataUtils {

    public static String[] weeks = new String[]{"星期日","星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

    public static String getWeekOfDate(long time) {

        Date date = new Date(time);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;

        return weeks[w];
    }

    public static String getFormatHour(String dateString) {
//        String dateString = weatherPerHour.getWeatherdata().get(i).getBj_datetime();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=null;
        try {
            date= simpleDateFormat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        } finally {
            if (date!=null) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                return  calendar.get(Calendar.HOUR_OF_DAY)+"时";
            }
            return "";
        }
    }


    public static String getDate() {
        Calendar calendar = Calendar.getInstance();
        StringBuilder builder = new StringBuilder();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        builder.append(sdf.format(calendar.getTime()));
        Lunar lunar = new Lunar(calendar);
        builder.append(" (");
        builder.append(lunar.toMonthString());
        builder.append(") ");
        builder.append(weeks[calendar.get(Calendar.DAY_OF_WEEK)-1]);
        return builder.toString();
    }
}
